{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Pandas怎样新增数据列？\n",
    "在进行数据分析时，经常需要按照一定条件创建新的数据列，然后进行下一步分析。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. 直接赋值 <br>\n",
    "2. df.apply方法<br>\n",
    "3. df.assign方法<br>\n",
    "4. 按条件选择分组分别赋值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 0. 读取csv数据到DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "fpath=\"../datas/weather_20230115134249.csv\"\n",
    "df = pd.read_csv(fpath)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-01-01</td>\n",
       "      <td>新北市</td>\n",
       "      <td>烏來區</td>\n",
       "      <td>福山</td>\n",
       "      <td>13.7℃</td>\n",
       "      <td>92</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-01-02</td>\n",
       "      <td>臺南市</td>\n",
       "      <td>安平區</td>\n",
       "      <td>安平</td>\n",
       "      <td>23.5℃</td>\n",
       "      <td>70</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2015-01-03</td>\n",
       "      <td>臺東縣</td>\n",
       "      <td>東河鄉</td>\n",
       "      <td>七塊厝</td>\n",
       "      <td>19.6℃</td>\n",
       "      <td>86</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2015-01-04</td>\n",
       "      <td>新北市</td>\n",
       "      <td>貢寮區</td>\n",
       "      <td>福隆</td>\n",
       "      <td>14.2℃</td>\n",
       "      <td>96</td>\n",
       "      <td>-99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2015-01-05</td>\n",
       "      <td>南投縣</td>\n",
       "      <td>仁愛鄉</td>\n",
       "      <td>小奇萊</td>\n",
       "      <td>8.3℃</td>\n",
       "      <td>57</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           日期   城市  行政区  观测站  气温(度)  相对湿度(%)  累积雨量(mm)\n",
       "0  2015-01-01  新北市  烏來區   福山  13.7℃       92       0.0\n",
       "1  2015-01-02  臺南市  安平區   安平  23.5℃       70       0.0\n",
       "2  2015-01-03  臺東縣  東河鄉  七塊厝  19.6℃       86       0.0\n",
       "3  2015-01-04  新北市  貢寮區   福隆  14.2℃       96     -99.0\n",
       "4  2015-01-05  南投縣  仁愛鄉  小奇萊   8.3℃       57       0.0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. 直接赋值的方法\n",
    "实例：清理温度列，变成数字类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 替换掉温度的后缀℃\n",
    "df.loc[:,\"气温(度)\"] = df[\"气温(度)\"].str.replace(\"℃\",\"\").astype(\"float\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "实例：计算温度差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 注意，df[\"气温(度)\"]其实是一个Series，后面的减法返回的是Series\n",
    "df.loc[:,\"wencha\"]=df[\"气温(度)\"]-2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "      <th>wencha</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-01-01</td>\n",
       "      <td>新北市</td>\n",
       "      <td>烏來區</td>\n",
       "      <td>福山</td>\n",
       "      <td>13.7</td>\n",
       "      <td>92</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-01-02</td>\n",
       "      <td>臺南市</td>\n",
       "      <td>安平區</td>\n",
       "      <td>安平</td>\n",
       "      <td>23.5</td>\n",
       "      <td>70</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2015-01-03</td>\n",
       "      <td>臺東縣</td>\n",
       "      <td>東河鄉</td>\n",
       "      <td>七塊厝</td>\n",
       "      <td>19.6</td>\n",
       "      <td>86</td>\n",
       "      <td>0.0</td>\n",
       "      <td>17.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2015-01-04</td>\n",
       "      <td>新北市</td>\n",
       "      <td>貢寮區</td>\n",
       "      <td>福隆</td>\n",
       "      <td>14.2</td>\n",
       "      <td>96</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>12.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2015-01-05</td>\n",
       "      <td>南投縣</td>\n",
       "      <td>仁愛鄉</td>\n",
       "      <td>小奇萊</td>\n",
       "      <td>8.3</td>\n",
       "      <td>57</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6.3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           日期   城市  行政区  观测站  气温(度)  相对湿度(%)  累积雨量(mm)  wencha\n",
       "0  2015-01-01  新北市  烏來區   福山   13.7       92       0.0    11.7\n",
       "1  2015-01-02  臺南市  安平區   安平   23.5       70       0.0    21.5\n",
       "2  2015-01-03  臺東縣  東河鄉  七塊厝   19.6       86       0.0    17.6\n",
       "3  2015-01-04  新北市  貢寮區   福隆   14.2       96     -99.0    12.2\n",
       "4  2015-01-05  南投縣  仁愛鄉  小奇萊    8.3       57       0.0     6.3"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##  2. df.apply方法\n",
    "Apply a function along an axis of the DataFrame.\n",
    "\n",
    "Object passed to the function are Series objects whose index is either the DataFrame's index(axis=0) or the DataFrame's columns(axis=1).\n",
    "\n",
    "实例：添加一列温度类型：\n",
    "* 如果最高温度大于33度就是高温\n",
    "* 低于-5度就是低温\n",
    "* 否则就是常温"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_wendu_type(x):\n",
    "    if x[\"气温(度)\"] > 33:\n",
    "        return '高温'\n",
    "    if x[\"气温(度)\"] < -10:\n",
    "        return '低温'\n",
    "    return '常温'\n",
    "\n",
    "# 注意需要设置axis==1,这是Series的index是columns\n",
    "df.loc[:,\"wendu_type\"] = df.apply(get_wendu_type,axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "常温    473\n",
       "低温     11\n",
       "Name: wendu_type, dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看 温度类型的计数\n",
    "df[\"wendu_type\"].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.df.assign方法\n",
    "Assign new columns to a DataFrame.\n",
    "Return a new object with all original columns in addition to new ones.\n",
    "\n",
    "实例：将温度从摄氏度变成华氏度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>城市</th>\n",
       "      <th>行政区</th>\n",
       "      <th>观测站</th>\n",
       "      <th>气温(度)</th>\n",
       "      <th>相对湿度(%)</th>\n",
       "      <th>累积雨量(mm)</th>\n",
       "      <th>wencha</th>\n",
       "      <th>wendu_type</th>\n",
       "      <th>tem_huashi</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2015-01-01</td>\n",
       "      <td>新北市</td>\n",
       "      <td>烏來區</td>\n",
       "      <td>福山</td>\n",
       "      <td>13.7</td>\n",
       "      <td>92</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11.7</td>\n",
       "      <td>常温</td>\n",
       "      <td>56.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2015-01-02</td>\n",
       "      <td>臺南市</td>\n",
       "      <td>安平區</td>\n",
       "      <td>安平</td>\n",
       "      <td>23.5</td>\n",
       "      <td>70</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.5</td>\n",
       "      <td>常温</td>\n",
       "      <td>74.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2015-01-03</td>\n",
       "      <td>臺東縣</td>\n",
       "      <td>東河鄉</td>\n",
       "      <td>七塊厝</td>\n",
       "      <td>19.6</td>\n",
       "      <td>86</td>\n",
       "      <td>0.0</td>\n",
       "      <td>17.6</td>\n",
       "      <td>常温</td>\n",
       "      <td>67.28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2015-01-04</td>\n",
       "      <td>新北市</td>\n",
       "      <td>貢寮區</td>\n",
       "      <td>福隆</td>\n",
       "      <td>14.2</td>\n",
       "      <td>96</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>12.2</td>\n",
       "      <td>常温</td>\n",
       "      <td>57.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2015-01-05</td>\n",
       "      <td>南投縣</td>\n",
       "      <td>仁愛鄉</td>\n",
       "      <td>小奇萊</td>\n",
       "      <td>8.3</td>\n",
       "      <td>57</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6.3</td>\n",
       "      <td>常温</td>\n",
       "      <td>46.94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2015-01-06</td>\n",
       "      <td>嘉義縣</td>\n",
       "      <td>大林鎮</td>\n",
       "      <td>大林</td>\n",
       "      <td>23.2</td>\n",
       "      <td>63</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.2</td>\n",
       "      <td>常温</td>\n",
       "      <td>73.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2015-01-07</td>\n",
       "      <td>花蓮縣</td>\n",
       "      <td>玉里鎮</td>\n",
       "      <td>玉里</td>\n",
       "      <td>18.5</td>\n",
       "      <td>85</td>\n",
       "      <td>0.0</td>\n",
       "      <td>16.5</td>\n",
       "      <td>常温</td>\n",
       "      <td>65.30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2015-01-08</td>\n",
       "      <td>嘉義市</td>\n",
       "      <td>東區</td>\n",
       "      <td>嘉義市東區</td>\n",
       "      <td>25.0</td>\n",
       "      <td>64</td>\n",
       "      <td>0.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>常温</td>\n",
       "      <td>77.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2015-01-09</td>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>頭城鎮</td>\n",
       "      <td>龜山島</td>\n",
       "      <td>12.0</td>\n",
       "      <td>100</td>\n",
       "      <td>0.5</td>\n",
       "      <td>10.0</td>\n",
       "      <td>常温</td>\n",
       "      <td>53.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2015-01-10</td>\n",
       "      <td>新北市</td>\n",
       "      <td>平溪區</td>\n",
       "      <td>火燒寮</td>\n",
       "      <td>12.3</td>\n",
       "      <td>100</td>\n",
       "      <td>2.5</td>\n",
       "      <td>10.3</td>\n",
       "      <td>常温</td>\n",
       "      <td>54.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2015-01-11</td>\n",
       "      <td>彰化縣</td>\n",
       "      <td>大城鄉</td>\n",
       "      <td>三豐</td>\n",
       "      <td>17.4</td>\n",
       "      <td>81</td>\n",
       "      <td>0.0</td>\n",
       "      <td>15.4</td>\n",
       "      <td>常温</td>\n",
       "      <td>63.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2015-01-12</td>\n",
       "      <td>雲林縣</td>\n",
       "      <td>斗六市</td>\n",
       "      <td>斗六</td>\n",
       "      <td>23.0</td>\n",
       "      <td>58</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>常温</td>\n",
       "      <td>73.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2015-01-13</td>\n",
       "      <td>南投縣</td>\n",
       "      <td>魚池鄉</td>\n",
       "      <td>魚池</td>\n",
       "      <td>26.3</td>\n",
       "      <td>50</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.3</td>\n",
       "      <td>常温</td>\n",
       "      <td>79.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2015-01-14</td>\n",
       "      <td>臺東縣</td>\n",
       "      <td>海端鄉</td>\n",
       "      <td>向陽</td>\n",
       "      <td>16.3</td>\n",
       "      <td>71</td>\n",
       "      <td>0.0</td>\n",
       "      <td>14.3</td>\n",
       "      <td>常温</td>\n",
       "      <td>61.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2015-01-15</td>\n",
       "      <td>屏東縣</td>\n",
       "      <td>竹田鄉</td>\n",
       "      <td>竹田</td>\n",
       "      <td>26.7</td>\n",
       "      <td>80</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.7</td>\n",
       "      <td>常温</td>\n",
       "      <td>80.06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2015-01-16</td>\n",
       "      <td>苗栗縣</td>\n",
       "      <td>造橋鄉</td>\n",
       "      <td>造橋</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-101.0</td>\n",
       "      <td>低温</td>\n",
       "      <td>-146.20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2015-01-17</td>\n",
       "      <td>新北市</td>\n",
       "      <td>石門區</td>\n",
       "      <td>白沙灣</td>\n",
       "      <td>13.7</td>\n",
       "      <td>90</td>\n",
       "      <td>8.5</td>\n",
       "      <td>11.7</td>\n",
       "      <td>常温</td>\n",
       "      <td>56.66</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2015-01-18</td>\n",
       "      <td>苗栗縣</td>\n",
       "      <td>頭屋鄉</td>\n",
       "      <td>明德</td>\n",
       "      <td>17.0</td>\n",
       "      <td>65</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>常温</td>\n",
       "      <td>62.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2015-01-19</td>\n",
       "      <td>臺南市</td>\n",
       "      <td>下營區</td>\n",
       "      <td>下營</td>\n",
       "      <td>26.2</td>\n",
       "      <td>58</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.2</td>\n",
       "      <td>常温</td>\n",
       "      <td>79.16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2015-01-20</td>\n",
       "      <td>屏東縣</td>\n",
       "      <td>萬丹鄉</td>\n",
       "      <td>萬丹</td>\n",
       "      <td>27.0</td>\n",
       "      <td>62</td>\n",
       "      <td>0.0</td>\n",
       "      <td>25.0</td>\n",
       "      <td>常温</td>\n",
       "      <td>80.60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>2015-01-21</td>\n",
       "      <td>新北市</td>\n",
       "      <td>三峽區</td>\n",
       "      <td>三峽</td>\n",
       "      <td>16.5</td>\n",
       "      <td>67</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>14.5</td>\n",
       "      <td>常温</td>\n",
       "      <td>61.70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>2015-01-22</td>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>頭城鎮</td>\n",
       "      <td>桃源谷</td>\n",
       "      <td>11.3</td>\n",
       "      <td>100</td>\n",
       "      <td>20.0</td>\n",
       "      <td>9.3</td>\n",
       "      <td>常温</td>\n",
       "      <td>52.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>2015-01-23</td>\n",
       "      <td>彰化縣</td>\n",
       "      <td>大城鄉</td>\n",
       "      <td>大城</td>\n",
       "      <td>19.2</td>\n",
       "      <td>72</td>\n",
       "      <td>0.0</td>\n",
       "      <td>17.2</td>\n",
       "      <td>常温</td>\n",
       "      <td>66.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>2015-01-24</td>\n",
       "      <td>臺中市</td>\n",
       "      <td>大里區</td>\n",
       "      <td>大里</td>\n",
       "      <td>24.3</td>\n",
       "      <td>50</td>\n",
       "      <td>0.0</td>\n",
       "      <td>22.3</td>\n",
       "      <td>常温</td>\n",
       "      <td>75.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>2015-01-25</td>\n",
       "      <td>臺中市</td>\n",
       "      <td>西屯區</td>\n",
       "      <td>西屯</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-101.0</td>\n",
       "      <td>低温</td>\n",
       "      <td>-146.20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2015-01-26</td>\n",
       "      <td>臺東縣</td>\n",
       "      <td>鹿野鄉</td>\n",
       "      <td>鹿野</td>\n",
       "      <td>18.2</td>\n",
       "      <td>85</td>\n",
       "      <td>0.0</td>\n",
       "      <td>16.2</td>\n",
       "      <td>常温</td>\n",
       "      <td>64.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2015-01-27</td>\n",
       "      <td>嘉義縣</td>\n",
       "      <td>太保市</td>\n",
       "      <td>太保</td>\n",
       "      <td>23.9</td>\n",
       "      <td>61</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.9</td>\n",
       "      <td>常温</td>\n",
       "      <td>75.02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2015-01-28</td>\n",
       "      <td>臺南市</td>\n",
       "      <td>學甲區</td>\n",
       "      <td>學甲</td>\n",
       "      <td>22.2</td>\n",
       "      <td>66</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.2</td>\n",
       "      <td>常温</td>\n",
       "      <td>71.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>2015-01-29</td>\n",
       "      <td>屏東縣</td>\n",
       "      <td>新園鄉</td>\n",
       "      <td>新園</td>\n",
       "      <td>25.4</td>\n",
       "      <td>76</td>\n",
       "      <td>0.0</td>\n",
       "      <td>23.4</td>\n",
       "      <td>常温</td>\n",
       "      <td>77.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>2015-01-30</td>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>頭城鎮</td>\n",
       "      <td>大溪漁港</td>\n",
       "      <td>14.9</td>\n",
       "      <td>87</td>\n",
       "      <td>8.0</td>\n",
       "      <td>12.9</td>\n",
       "      <td>常温</td>\n",
       "      <td>58.82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>454</th>\n",
       "      <td>2016-03-30</td>\n",
       "      <td>臺南市</td>\n",
       "      <td>白河區</td>\n",
       "      <td>鹿寮</td>\n",
       "      <td>23.0</td>\n",
       "      <td>74</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>常温</td>\n",
       "      <td>73.40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>455</th>\n",
       "      <td>2016-03-31</td>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>壯圍鄉</td>\n",
       "      <td>大福</td>\n",
       "      <td>17.3</td>\n",
       "      <td>79</td>\n",
       "      <td>0.0</td>\n",
       "      <td>15.3</td>\n",
       "      <td>常温</td>\n",
       "      <td>63.14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>456</th>\n",
       "      <td>2016-04-01</td>\n",
       "      <td>臺東縣</td>\n",
       "      <td>達仁鄉</td>\n",
       "      <td>達仁林場</td>\n",
       "      <td>17.9</td>\n",
       "      <td>97</td>\n",
       "      <td>0.0</td>\n",
       "      <td>15.9</td>\n",
       "      <td>常温</td>\n",
       "      <td>64.22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>457</th>\n",
       "      <td>2016-04-02</td>\n",
       "      <td>雲林縣</td>\n",
       "      <td>東勢鄉</td>\n",
       "      <td>雲林東勢</td>\n",
       "      <td>19.9</td>\n",
       "      <td>71</td>\n",
       "      <td>0.0</td>\n",
       "      <td>17.9</td>\n",
       "      <td>常温</td>\n",
       "      <td>67.82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>458</th>\n",
       "      <td>2016-04-03</td>\n",
       "      <td>屏東縣</td>\n",
       "      <td>牡丹鄉</td>\n",
       "      <td>四林格山</td>\n",
       "      <td>19.2</td>\n",
       "      <td>94</td>\n",
       "      <td>0.0</td>\n",
       "      <td>17.2</td>\n",
       "      <td>常温</td>\n",
       "      <td>66.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>459</th>\n",
       "      <td>2016-04-04</td>\n",
       "      <td>屏東縣</td>\n",
       "      <td>牡丹鄉</td>\n",
       "      <td>牡丹</td>\n",
       "      <td>22.8</td>\n",
       "      <td>79</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.8</td>\n",
       "      <td>常温</td>\n",
       "      <td>73.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>460</th>\n",
       "      <td>2016-04-05</td>\n",
       "      <td>嘉義縣</td>\n",
       "      <td>布袋鎮</td>\n",
       "      <td>布袋</td>\n",
       "      <td>21.4</td>\n",
       "      <td>69</td>\n",
       "      <td>0.0</td>\n",
       "      <td>19.4</td>\n",
       "      <td>常温</td>\n",
       "      <td>70.52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>461</th>\n",
       "      <td>2016-04-06</td>\n",
       "      <td>南投縣</td>\n",
       "      <td>竹山鎮</td>\n",
       "      <td>竹山</td>\n",
       "      <td>24.6</td>\n",
       "      <td>66</td>\n",
       "      <td>0.0</td>\n",
       "      <td>22.6</td>\n",
       "      <td>常温</td>\n",
       "      <td>76.28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>462</th>\n",
       "      <td>2016-04-07</td>\n",
       "      <td>高雄市</td>\n",
       "      <td>田寮區</td>\n",
       "      <td>古亭坑</td>\n",
       "      <td>26.4</td>\n",
       "      <td>67</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.4</td>\n",
       "      <td>常温</td>\n",
       "      <td>79.52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>463</th>\n",
       "      <td>2016-04-08</td>\n",
       "      <td>桃園市</td>\n",
       "      <td>龜山區</td>\n",
       "      <td>國一五楊N44K</td>\n",
       "      <td>12.5</td>\n",
       "      <td>85</td>\n",
       "      <td>8.0</td>\n",
       "      <td>10.5</td>\n",
       "      <td>常温</td>\n",
       "      <td>54.50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>464</th>\n",
       "      <td>2016-04-09</td>\n",
       "      <td>新北市</td>\n",
       "      <td>坪林區</td>\n",
       "      <td>四堵</td>\n",
       "      <td>13.8</td>\n",
       "      <td>88</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11.8</td>\n",
       "      <td>常温</td>\n",
       "      <td>56.84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>465</th>\n",
       "      <td>2016-04-10</td>\n",
       "      <td>屏東縣</td>\n",
       "      <td>鹽埔鄉</td>\n",
       "      <td>鹽埔</td>\n",
       "      <td>28.3</td>\n",
       "      <td>73</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>26.3</td>\n",
       "      <td>常温</td>\n",
       "      <td>82.94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>466</th>\n",
       "      <td>2016-04-11</td>\n",
       "      <td>臺東縣</td>\n",
       "      <td>臺東市</td>\n",
       "      <td>知本(水試所)</td>\n",
       "      <td>22.7</td>\n",
       "      <td>72</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.7</td>\n",
       "      <td>常温</td>\n",
       "      <td>72.86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>467</th>\n",
       "      <td>2016-04-12</td>\n",
       "      <td>南投縣</td>\n",
       "      <td>中寮鄉</td>\n",
       "      <td>中寮</td>\n",
       "      <td>24.2</td>\n",
       "      <td>59</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>22.2</td>\n",
       "      <td>常温</td>\n",
       "      <td>75.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>468</th>\n",
       "      <td>2016-04-13</td>\n",
       "      <td>臺南市</td>\n",
       "      <td>龍崎區</td>\n",
       "      <td>崎頂</td>\n",
       "      <td>25.1</td>\n",
       "      <td>75</td>\n",
       "      <td>0.0</td>\n",
       "      <td>23.1</td>\n",
       "      <td>常温</td>\n",
       "      <td>77.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>469</th>\n",
       "      <td>2016-04-14</td>\n",
       "      <td>苗栗縣</td>\n",
       "      <td>三義鄉</td>\n",
       "      <td>三義</td>\n",
       "      <td>15.3</td>\n",
       "      <td>91</td>\n",
       "      <td>2.0</td>\n",
       "      <td>13.3</td>\n",
       "      <td>常温</td>\n",
       "      <td>59.54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>470</th>\n",
       "      <td>2016-04-15</td>\n",
       "      <td>新北市</td>\n",
       "      <td>永和區</td>\n",
       "      <td>永和</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-9900</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>-101.0</td>\n",
       "      <td>低温</td>\n",
       "      <td>-146.20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>471</th>\n",
       "      <td>2016-04-16</td>\n",
       "      <td>屏東縣</td>\n",
       "      <td>來義鄉</td>\n",
       "      <td>白鷺</td>\n",
       "      <td>25.3</td>\n",
       "      <td>72</td>\n",
       "      <td>0.0</td>\n",
       "      <td>23.3</td>\n",
       "      <td>常温</td>\n",
       "      <td>77.54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>472</th>\n",
       "      <td>2016-04-17</td>\n",
       "      <td>屏東縣</td>\n",
       "      <td>滿州鄉</td>\n",
       "      <td>佳樂水</td>\n",
       "      <td>24.1</td>\n",
       "      <td>75</td>\n",
       "      <td>0.0</td>\n",
       "      <td>22.1</td>\n",
       "      <td>常温</td>\n",
       "      <td>75.38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>473</th>\n",
       "      <td>2016-04-18</td>\n",
       "      <td>臺南市</td>\n",
       "      <td>白河區</td>\n",
       "      <td>白河</td>\n",
       "      <td>23.4</td>\n",
       "      <td>68</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.4</td>\n",
       "      <td>常温</td>\n",
       "      <td>74.12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>474</th>\n",
       "      <td>2016-04-19</td>\n",
       "      <td>新竹縣</td>\n",
       "      <td>峨眉鄉</td>\n",
       "      <td>峨眉</td>\n",
       "      <td>16.6</td>\n",
       "      <td>73</td>\n",
       "      <td>5.5</td>\n",
       "      <td>14.6</td>\n",
       "      <td>常温</td>\n",
       "      <td>61.88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>475</th>\n",
       "      <td>2016-04-20</td>\n",
       "      <td>新北市</td>\n",
       "      <td>蘆洲區</td>\n",
       "      <td>蘆洲</td>\n",
       "      <td>17.6</td>\n",
       "      <td>71</td>\n",
       "      <td>-99.0</td>\n",
       "      <td>15.6</td>\n",
       "      <td>常温</td>\n",
       "      <td>63.68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>476</th>\n",
       "      <td>2016-04-21</td>\n",
       "      <td>屏東縣</td>\n",
       "      <td>萬巒鄉</td>\n",
       "      <td>來義</td>\n",
       "      <td>26.8</td>\n",
       "      <td>69</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.8</td>\n",
       "      <td>常温</td>\n",
       "      <td>80.24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>477</th>\n",
       "      <td>2016-04-22</td>\n",
       "      <td>新北市</td>\n",
       "      <td>三重區</td>\n",
       "      <td>三重</td>\n",
       "      <td>16.3</td>\n",
       "      <td>76</td>\n",
       "      <td>3.5</td>\n",
       "      <td>14.3</td>\n",
       "      <td>常温</td>\n",
       "      <td>61.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>478</th>\n",
       "      <td>2016-04-23</td>\n",
       "      <td>高雄市</td>\n",
       "      <td>茄萣區</td>\n",
       "      <td>興達</td>\n",
       "      <td>25.1</td>\n",
       "      <td>67</td>\n",
       "      <td>0.0</td>\n",
       "      <td>23.1</td>\n",
       "      <td>常温</td>\n",
       "      <td>77.18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>479</th>\n",
       "      <td>2016-04-24</td>\n",
       "      <td>新北市</td>\n",
       "      <td>板橋區</td>\n",
       "      <td>板橋</td>\n",
       "      <td>15.6</td>\n",
       "      <td>73</td>\n",
       "      <td>5.0</td>\n",
       "      <td>13.6</td>\n",
       "      <td>常温</td>\n",
       "      <td>60.08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>480</th>\n",
       "      <td>2016-04-25</td>\n",
       "      <td>宜蘭縣</td>\n",
       "      <td>大同鄉</td>\n",
       "      <td>翠峰湖</td>\n",
       "      <td>7.8</td>\n",
       "      <td>100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.8</td>\n",
       "      <td>常温</td>\n",
       "      <td>46.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>481</th>\n",
       "      <td>2016-04-26</td>\n",
       "      <td>花蓮縣</td>\n",
       "      <td>壽豐鄉</td>\n",
       "      <td>大坑</td>\n",
       "      <td>15.7</td>\n",
       "      <td>94</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.7</td>\n",
       "      <td>常温</td>\n",
       "      <td>60.26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>482</th>\n",
       "      <td>2016-04-27</td>\n",
       "      <td>新竹縣</td>\n",
       "      <td>五峰鄉</td>\n",
       "      <td>雪霸</td>\n",
       "      <td>15.7</td>\n",
       "      <td>62</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.7</td>\n",
       "      <td>常温</td>\n",
       "      <td>60.26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>483</th>\n",
       "      <td>2016-04-28</td>\n",
       "      <td>桃園市</td>\n",
       "      <td>大溪區</td>\n",
       "      <td>大溪</td>\n",
       "      <td>14.8</td>\n",
       "      <td>77</td>\n",
       "      <td>8.0</td>\n",
       "      <td>12.8</td>\n",
       "      <td>常温</td>\n",
       "      <td>58.64</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>484 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             日期   城市  行政区       观测站  气温(度)  相对湿度(%)  累积雨量(mm)  wencha  \\\n",
       "0    2015-01-01  新北市  烏來區        福山   13.7       92       0.0    11.7   \n",
       "1    2015-01-02  臺南市  安平區        安平   23.5       70       0.0    21.5   \n",
       "2    2015-01-03  臺東縣  東河鄉       七塊厝   19.6       86       0.0    17.6   \n",
       "3    2015-01-04  新北市  貢寮區        福隆   14.2       96     -99.0    12.2   \n",
       "4    2015-01-05  南投縣  仁愛鄉       小奇萊    8.3       57       0.0     6.3   \n",
       "5    2015-01-06  嘉義縣  大林鎮        大林   23.2       63       0.0    21.2   \n",
       "6    2015-01-07  花蓮縣  玉里鎮        玉里   18.5       85       0.0    16.5   \n",
       "7    2015-01-08  嘉義市   東區     嘉義市東區   25.0       64       0.0    23.0   \n",
       "8    2015-01-09  宜蘭縣  頭城鎮       龜山島   12.0      100       0.5    10.0   \n",
       "9    2015-01-10  新北市  平溪區       火燒寮   12.3      100       2.5    10.3   \n",
       "10   2015-01-11  彰化縣  大城鄉        三豐   17.4       81       0.0    15.4   \n",
       "11   2015-01-12  雲林縣  斗六市        斗六   23.0       58       0.0    21.0   \n",
       "12   2015-01-13  南投縣  魚池鄉        魚池   26.3       50       0.0    24.3   \n",
       "13   2015-01-14  臺東縣  海端鄉        向陽   16.3       71       0.0    14.3   \n",
       "14   2015-01-15  屏東縣  竹田鄉        竹田   26.7       80       0.0    24.7   \n",
       "15   2015-01-16  苗栗縣  造橋鄉        造橋  -99.0    -9900     -99.0  -101.0   \n",
       "16   2015-01-17  新北市  石門區       白沙灣   13.7       90       8.5    11.7   \n",
       "17   2015-01-18  苗栗縣  頭屋鄉        明德   17.0       65     -99.0    15.0   \n",
       "18   2015-01-19  臺南市  下營區        下營   26.2       58       0.0    24.2   \n",
       "19   2015-01-20  屏東縣  萬丹鄉        萬丹   27.0       62       0.0    25.0   \n",
       "20   2015-01-21  新北市  三峽區        三峽   16.5       67     -99.0    14.5   \n",
       "21   2015-01-22  宜蘭縣  頭城鎮       桃源谷   11.3      100      20.0     9.3   \n",
       "22   2015-01-23  彰化縣  大城鄉        大城   19.2       72       0.0    17.2   \n",
       "23   2015-01-24  臺中市  大里區        大里   24.3       50       0.0    22.3   \n",
       "24   2015-01-25  臺中市  西屯區        西屯  -99.0    -9900     -99.0  -101.0   \n",
       "25   2015-01-26  臺東縣  鹿野鄉        鹿野   18.2       85       0.0    16.2   \n",
       "26   2015-01-27  嘉義縣  太保市        太保   23.9       61       0.0    21.9   \n",
       "27   2015-01-28  臺南市  學甲區        學甲   22.2       66       0.0    20.2   \n",
       "28   2015-01-29  屏東縣  新園鄉        新園   25.4       76       0.0    23.4   \n",
       "29   2015-01-30  宜蘭縣  頭城鎮      大溪漁港   14.9       87       8.0    12.9   \n",
       "..          ...  ...  ...       ...    ...      ...       ...     ...   \n",
       "454  2016-03-30  臺南市  白河區        鹿寮   23.0       74       0.0    21.0   \n",
       "455  2016-03-31  宜蘭縣  壯圍鄉        大福   17.3       79       0.0    15.3   \n",
       "456  2016-04-01  臺東縣  達仁鄉      達仁林場   17.9       97       0.0    15.9   \n",
       "457  2016-04-02  雲林縣  東勢鄉      雲林東勢   19.9       71       0.0    17.9   \n",
       "458  2016-04-03  屏東縣  牡丹鄉      四林格山   19.2       94       0.0    17.2   \n",
       "459  2016-04-04  屏東縣  牡丹鄉        牡丹   22.8       79       0.0    20.8   \n",
       "460  2016-04-05  嘉義縣  布袋鎮        布袋   21.4       69       0.0    19.4   \n",
       "461  2016-04-06  南投縣  竹山鎮        竹山   24.6       66       0.0    22.6   \n",
       "462  2016-04-07  高雄市  田寮區       古亭坑   26.4       67       0.0    24.4   \n",
       "463  2016-04-08  桃園市  龜山區  國一五楊N44K   12.5       85       8.0    10.5   \n",
       "464  2016-04-09  新北市  坪林區        四堵   13.8       88       0.0    11.8   \n",
       "465  2016-04-10  屏東縣  鹽埔鄉        鹽埔   28.3       73     -99.0    26.3   \n",
       "466  2016-04-11  臺東縣  臺東市   知本(水試所)   22.7       72       0.0    20.7   \n",
       "467  2016-04-12  南投縣  中寮鄉        中寮   24.2       59     -99.0    22.2   \n",
       "468  2016-04-13  臺南市  龍崎區        崎頂   25.1       75       0.0    23.1   \n",
       "469  2016-04-14  苗栗縣  三義鄉        三義   15.3       91       2.0    13.3   \n",
       "470  2016-04-15  新北市  永和區        永和  -99.0    -9900     -99.0  -101.0   \n",
       "471  2016-04-16  屏東縣  來義鄉        白鷺   25.3       72       0.0    23.3   \n",
       "472  2016-04-17  屏東縣  滿州鄉       佳樂水   24.1       75       0.0    22.1   \n",
       "473  2016-04-18  臺南市  白河區        白河   23.4       68       0.0    21.4   \n",
       "474  2016-04-19  新竹縣  峨眉鄉        峨眉   16.6       73       5.5    14.6   \n",
       "475  2016-04-20  新北市  蘆洲區        蘆洲   17.6       71     -99.0    15.6   \n",
       "476  2016-04-21  屏東縣  萬巒鄉        來義   26.8       69       0.0    24.8   \n",
       "477  2016-04-22  新北市  三重區        三重   16.3       76       3.5    14.3   \n",
       "478  2016-04-23  高雄市  茄萣區        興達   25.1       67       0.0    23.1   \n",
       "479  2016-04-24  新北市  板橋區        板橋   15.6       73       5.0    13.6   \n",
       "480  2016-04-25  宜蘭縣  大同鄉       翠峰湖    7.8      100       0.0     5.8   \n",
       "481  2016-04-26  花蓮縣  壽豐鄉        大坑   15.7       94       0.0    13.7   \n",
       "482  2016-04-27  新竹縣  五峰鄉        雪霸   15.7       62       0.0    13.7   \n",
       "483  2016-04-28  桃園市  大溪區        大溪   14.8       77       8.0    12.8   \n",
       "\n",
       "    wendu_type  tem_huashi  \n",
       "0           常温       56.66  \n",
       "1           常温       74.30  \n",
       "2           常温       67.28  \n",
       "3           常温       57.56  \n",
       "4           常温       46.94  \n",
       "5           常温       73.76  \n",
       "6           常温       65.30  \n",
       "7           常温       77.00  \n",
       "8           常温       53.60  \n",
       "9           常温       54.14  \n",
       "10          常温       63.32  \n",
       "11          常温       73.40  \n",
       "12          常温       79.34  \n",
       "13          常温       61.34  \n",
       "14          常温       80.06  \n",
       "15          低温     -146.20  \n",
       "16          常温       56.66  \n",
       "17          常温       62.60  \n",
       "18          常温       79.16  \n",
       "19          常温       80.60  \n",
       "20          常温       61.70  \n",
       "21          常温       52.34  \n",
       "22          常温       66.56  \n",
       "23          常温       75.74  \n",
       "24          低温     -146.20  \n",
       "25          常温       64.76  \n",
       "26          常温       75.02  \n",
       "27          常温       71.96  \n",
       "28          常温       77.72  \n",
       "29          常温       58.82  \n",
       "..         ...         ...  \n",
       "454         常温       73.40  \n",
       "455         常温       63.14  \n",
       "456         常温       64.22  \n",
       "457         常温       67.82  \n",
       "458         常温       66.56  \n",
       "459         常温       73.04  \n",
       "460         常温       70.52  \n",
       "461         常温       76.28  \n",
       "462         常温       79.52  \n",
       "463         常温       54.50  \n",
       "464         常温       56.84  \n",
       "465         常温       82.94  \n",
       "466         常温       72.86  \n",
       "467         常温       75.56  \n",
       "468         常温       77.18  \n",
       "469         常温       59.54  \n",
       "470         低温     -146.20  \n",
       "471         常温       77.54  \n",
       "472         常温       75.38  \n",
       "473         常温       74.12  \n",
       "474         常温       61.88  \n",
       "475         常温       63.68  \n",
       "476         常温       80.24  \n",
       "477         常温       61.34  \n",
       "478         常温       77.18  \n",
       "479         常温       60.08  \n",
       "480         常温       46.04  \n",
       "481         常温       60.26  \n",
       "482         常温       60.26  \n",
       "483         常温       58.64  \n",
       "\n",
       "[484 rows x 10 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 可以同事添加多个新的列\n",
    "df.assign(\n",
    "    #摄氏度转华氏度\n",
    "    tem_huashi = lambda x : x[\"气温(度)\"] * 9 / 5 + 32\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4. 按条件选择分组分别赋值\n",
    "按条件先选择温度，然后对这部分数据赋值新列<br>\n",
    "实例：温度减去10度小于15度，则认为温差大"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 先创建空列（这是第一种创建新列的方法）\n",
    "df['wencha_type']=''\n",
    "df.loc[df[\"气温(度)\"]-10 < 15,\"wencha_type\"]=\"温差大\"\n",
    "df.loc[df[\"气温(度)\"]-10 >= 15,\"wencha_type\"]=\"温差正常\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "温差大     410\n",
       "温差正常     74\n",
       "Name: wencha_type, dtype: int64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[\"wencha_type\"].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
